home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Shareware
/
IDimager Personal 4.2.0.3
/
setup_IDimager_Personal_V4.exe
/
{app}
/
web
/
loadimage.psc
< prev
next >
Wrap
Text File
|
2008-06-27
|
6KB
|
232 lines
%code
procedure DoResizeImage (AJpg: TImageItem; ASize: Integer);
var
AEp: TEffectProcessor;
ARes: TResizeSettings;
begin
if (ASize < 5) then
exit;
// already at the right size?
if ASize = Max(AJpg.Graphic.Width, AJpg.Graphic.Height) then
exit;
if (ASize > 5000) then
ASize := 5000;
AEp := TEffectProcessor.Create (nil, False);
ARes := TResizeSettings.Create(nil);
ARes.Width := ASize;
ARes.Height := ASize;
AEp.EffectResize (AJpg, ARes);
ARes.Free;
AEp.Free;
end;
procedure MakeImageSquare (AJpg: TImageItem);
var
AEp: TEffectProcessor;
begin
AEp := TEffectProcessor.Create (nil, False);
AEp.EffectCropToRatio (AJpg, 1, 1, False);
AEp.Free;
end;
procedure DoResize (AItem: TCatalogItem; var AStream: TStream; ASize: Integer);
var
AJpg: TImageItem;
AJpgGr: TJPegGraphic;
begin
if ASize < 5 then
exit;
AJpg := TImageItem.Create(nil);
AJpg.NewGraphic ('*.jpg');
AStream.Position := 0;
AJpg.Graphic.LoadFromStream (AStream);
if ASize > Max(AJpg.Graphic.Width, AJpg.Graphic.Height) then
begin
// load the full image
AItem.PushToImage (AJpg, False);
AJpg.Graphic.Clear;
AJpg.NewGraphic (AJpg.FileName);
AJpg._Load (True, True, True, ASize);
end;
AJpgGr := AJpg.Graphic;
AJpgGr.SaveQuality := Options.JPGQuality;
DoResizeImage (AJpg, ASize);
AStream.Size := 0;
AJpg.Graphic.SaveToStream (AStream);
AStream.Position := 0;
AJpg.Free;
end;
procedure MakeSquare (AItem: TCatalogItem; var AStream: TStream);
var
AJpg: TImageItem;
AJpgGr: TJPegGraphic;
begin
AJpg := TImageItem.Create(nil);
AJpg.NewGraphic ('*.jpg');
AStream.Position := 0;
AJpg.Graphic.LoadFromStream (AStream);
AJpgGr := AJpg.Graphic;
AJpgGr.SaveQuality := Options.JPGQuality;
MakeImageSquare (AJpg);
AStream.Size := 0;
AJpg.Graphic.SaveToStream (AStream);
AStream.Position := 0;
AJpg.Free;
end;
procedure MakeSquareAndResize (AItem: TCatalogItem; var AStream: TStream; ASize: Integer);
var
AJpg: TImageItem;
AJpgGr: TJpegGraphic;
begin
AJpg := TImageItem.Create(nil);
AJpg.NewGraphic ('*.jpg');
AStream.Position := 0;
AJpg.Graphic.LoadFromStream (AStream);
if (ASize > Max(AJpg.Graphic.Width, AJpg.Graphic.Height)) then
begin
// load the full image
AItem.PushToImage (AJpg, False);
AJpg.Graphic.Clear;
AJpg.NewGraphic (AJpg.FileName);
AJpg._Load (True, True, True, ASize);
if not AJpg.IsJpeg then
begin
AJpgGr := TJpegGraphic.Create;
AJpgGr.Assign (AJpg.Graphic);
AJpg.Graphic.Free;
AJpg.Graphic := AJpgGr;
end;
end;
AJpgGr := AJpg.Graphic;
AJpgGr.SaveQuality := Options.JPGQuality;
MakeImageSquare (AJpg);
DoResizeImage (AJpg, ASize);
AStream.Size := 0;
AJpg.Graphic.SaveToStream (AStream);
AStream.Position := 0;
AJpg.Free;
end;
var
AItem: TCatalogItem;
ARs: TMemoryStream;
AFs: TTntFileStream;
AForcedThumb: Boolean;
AAllowOriginal: Boolean;
ASize: Integer;
begin
//AAllowOriginal := Nvl(SessionData.Prop['IsAdmin'], False);
AAllowOriginal := True;
if IsValidNumberString(Request.Params.Values['size'], False) then
begin
ASize := StrToInt(Request.Params.Values['size']);
if ASize < 0 then
ASize := 0;
end
else
ASize := 0;
AItem := TCatalogItem.Create(nil);
if Catalog.FindItemCombinedByGUID (Request.Params.Values['image'], AItem) and
(
(
(AItem.HasThumb) or (AItem.HasMedium)
) or
(AAllowOriginal and (Request.Params.Values['original'] = '1'))
)
then
begin
Response.CustomHeaders.Add ('Content-Disposition=inline;filename="' + UTF8Encode(WideExtractFileName (AItem.FileName)) + '"');
if (Request.Params.Values['quality'] = '1') then
AForcedThumb := False
else
begin
AForcedThumb := (Request.Params.Values['thumb'] = '1');
if AForcedThumb and (ASize > Options.ThumbSize) then
AForcedThumb := False;
end;
ARs := TMemoryStream.Create;
if AAllowOriginal and (Request.Params.Values['original'] = '1') and (AItem.MediumLoaded) and WideFileExists(AItem.FileName) then
begin
//ARs.LoadFromFile (AItem.FileName)
AFs := TTntFileStream.Create (AItem.FileName, fmOpenRead or fmShareDenyNone);
if Request.Params.Values['download'] = '1' then
begin
Response.CustomHeaders.Clear;
Response.CustomHeaders.Add ('Content-Disposition=attachment;filename="' + UTF8Encode(WideExtractFileName (AItem.FileName)) + '"');
Response.ContentType := 'application/octet-stream'
end
else
Response.ContentType := FileMimeType (AItem.FileName);
Response.ContentStream := AFs;
Response.ContentLength := AFs.Size;
Response.FreeContentStream := True;
//Response.WriteContent;
exit;
end
else if (not AForcedThumb) and AItem.HasMedium then
AItem.LoadMediumFromFile (ARs)
else
AItem.LoadThumbFromFile (ARs);
if (Request.Params.Values['square'] = '1') and
(ASize > 0)
then
MakeSquareAndResize (AItem, ARs, ASize)
else
begin
if Request.Params.Values['square'] = '1' then
MakeSquare (AItem, ARs);
if ASize > 0 then
DoResize (AItem, ARs, ASize);
end;
Response.ContentType := 'image/jpeg';
Response.ContentStream := ARs;
Response.ContentLength := ARs.Size;
Response.FreeContentStream := True;
Response.WriteContent;
// ARs.Free; // don't free the stream because the streamer will do that since FreeContentStream is set
end;
AItem.Free;
end;
%/code